package com.xkdx.guangguang.adapter;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.xkdx.caipiao.R;
import com.xkdx.guangguang.shareclass.BrandDetail;

public class BrandAdapter extends BaseAdapter {

		String url;
		Context context;
		List<BrandDetail> list;
		ImageLoader imageLoader;
		DisplayImageOptions options = new DisplayImageOptions.Builder().showStubImage(R.drawable.empty_photo)
				.showImageForEmptyUri(R.drawable.empty_photo).showImageOnFail(R.drawable.empty_photo)
				.resetViewBeforeLoading().cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY)
				.bitmapConfig(Bitmap.Config.RGB_565).build();

		public BrandAdapter(Context context, List<BrandDetail> list,ImageLoader imageLoader) {
			super();
			this.list = list;
			this.context = context;
			this.imageLoader=imageLoader;
			
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ViewHodler viewHolder;
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(R.layout.brand_item, null);
				viewHolder = new ViewHodler();
				viewHolder.image = (ImageView) convertView.findViewById(R.id.brand_image);
				viewHolder.name = (TextView) convertView.findViewById(R.id.brand_item_name);
				viewHolder.ll = (LinearLayout) convertView.findViewById(R.id.brand_item_linearLayout);
				convertView.setTag(viewHolder);
			} else {
				viewHolder = (ViewHodler) convertView.getTag();
			}

			url = list.get(position).getLogo();
			viewHolder.name.setText(list.get(position).getBrandSimpleName());

			imageLoader.displayImage(url, viewHolder.image, options);

			return convertView;
		}

		class ViewHodler {
			TextView name;
			ImageView image;
			LinearLayout ll;
		}

	}